package com.kaifamiao.strings;

import java.util.Scanner;

/**
 * 1、String trim()
 * 2、String strip()
 * 3、String stripLeading()
 * 4、String stripTrailing()
 */
public class TrimString {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println( "请输入密码" );
        String s = sc.nextLine();
        System.out.println( s.length() );
        System.out.println( s );

        // 剔除字符串首尾空白后返回新字符串
        String x = s.trim();
        System.out.println( x.length() );
        System.out.println( x );

        sc.close();

        System.out.println( "- ".repeat( 15 ) );

        String p = "    hello, kaifamiao .  ";
        System.out.println( p.length() );

        // 剔除字符串首尾空白后返回新字符串
        String t = p.strip(); // Java 11
        System.out.println( t.length() );
        System.out.printf( "|%s|\n", t );

        // 仅剔除字符串首部空白后返回新字符串
        String h = p.stripLeading(); // Java 11
        System.out.printf( "|%s|\n", h );

        // 仅剔除字符串尾部空白后返回新字符串
        String u = p.stripTrailing(); // Java 11
        System.out.printf( "|%s|\n", u );
    }

}
